//special thanks to Golden, Ors, and Nightwolf
local function nomissile(actor)
	// possibly choose another target
	if (multiplayer and not actor.threshold and (actor.target.health <= 0 or not P_CheckSight(actor, actor.target))
		and P_LookForPlayers(actor, 0, true, false))
		return // got a new target
	end
	// chase towards player
	actor.movecount = $1 - 1 
	if (actor.movecount < 0 or not P_Move(actor, actor.info.speed))
		P_NewChaseDir(actor)
	end
end
function A_PlasmaChase(actor)
	local delta
	if not actor.target
	return
	end

	assert(actor)
	assert(actor.valid)
	actor.reactiontime = actor.info.reactiontime

	// modify target threshold
	if (actor.threshold)
		if (not actor.target or actor.target.health <= 0)
			actor.threshold = 0
		else
			actor.threshold = $1 - 1
		end
	end
	// turn towards movement direction if not there yet
	if (actor.movedir < NUMDIRS)
		actor.angle = $1 & (7<<29)
		delta = actor.angle - (actor.movedir << 29)

		if (delta > 0)
			actor.angle = $-ANGLE_45
		elseif (delta < 0)
			actor.angle = $+ANGLE_45
		end
	end
	if (not actor.target or not (actor.target.flags & MF_SHOOTABLE))
		// look for a new target
		if (P_LookForPlayers(actor, 0, true, false))
			return // got a new target
		end

		P_SetMobjStateNF(actor, actor.info.spawnstate)
		return
	end
	// do not attack twice in a row
	if (actor.flags2 & MF2_JUSTATTACKED)
		actor.flags2 = $1 & ~MF2_JUSTATTACKED
		P_NewChaseDir(actor)
		return
	end
	nomissile(actor)
end

//Drone Check by Glaber
function A_DroneCheck(actor)
	actor.momz = 2*FRACUNIT
	if (actor.z + actor.height >= actor.ceilingz)
		actor.state = actor.info.spawnstate
	end
end


//particle spawner action Made and Optmized by Midiman

// Spawn energy particles
function A_ParticleVacuumPD(mobj)
	if not (mobj and mobj.valid) then return end
	
	local dist = 0
	
	local spawner = mobj.hnext
	while spawner and spawner.valid do
		dist = FixedHypot(spawner.x - mobj.x, spawner.y - mobj.y)
		if (P_RandomRange(1,dist/FRACUNIT/16) == 1) then
			break
		end
		spawner = spawner.hnext
	end
	if spawner and spawner.valid then
		local missile = P_SpawnMissile(spawner, mobj, MT_MSGATHER) // Replace MT_MSGATHER with MT_TGFGATHER once made
		// Make the particles faster
		missile.momx = $*2
		missile.momy = $*2
		missile.momz = $*2
		//missile.momz = FixedDiv(missile.momz, 7*FRACUNIT/4)
		if dist == 0 then
			missile.fuse = 0
		else
			missile.fuse = dist/FixedHypot(missile.momx, missile.momy)
		end
		//if missile.fuse > mobj.fuse then
			//P_RemoveMobj(missile)
		//end
	end
end